﻿using System;
using Windows.UI.Xaml.Data;
using Windows.UI.Xaml.Media.Imaging;

namespace Smile.Xaml.Converter
{
    /// <summary>URI to image converter.</summary>
    public class UriToImageConverter : IValueConverter
    {
        // @Public
        public object Convert(object value, Type targetType, object parameter, string language)
        {
            try
            {
                var uri = new Uri((string)value, UriKind.Absolute);
                var image = new BitmapImage(uri);
                image.CreateOptions = BitmapCreateOptions.None;
                return image;
            }
            catch
            {
                return new BitmapImage();
            }
        }

        public object ConvertBack(object value, Type targetType, object parameter, string language)
        {
            throw new NotImplementedException();
        }
    }
}
